<?php 
/* 
 * Template Name: contact
 * 
 */
?>
<?php get_header(); ?>
<?php 
$contact = get_param("contact", NULL);
$msg = "";
if (NULL != $contact && $contact['action'] == 1) {
	//print "<pre>";	
	//print_r($contact);
	//print "</pre>";
	
	if (empty($contact['fullname']) || is_numeric($contact['fullname'])) {
		$msg .= "<br />Full name is invalid.";
	}
	if (empty($contact['email']) || !vt_validate_email($contact['email'])) {
		$msg .= "<br />Email is invalid";
	}
	if (!empty($contact['phone']) && !is_numeric($contact['phone'])) {
		$msg .= "<br />Phone number is invalid.";
	}
	if (empty($contact['content'])) {
		$msg .= "<br />Content is invalid.";
	}
	if (empty($msg)) {
		//Send mail to reciever account
		$mail_to = get_option('receive_email');
		$mail_subject = "Request from: ".$contact['fullname']."<".$contact['email'].">";
		$mail_content = "<strong>Customer: </strong>".$contact['fullname']."<br />"
				."<strong>Email: </strong>".$contact['email']."<br />"
				."<strong>Phone number: </strong>".$contact['phone']."<br />"
				."<strong>Content:</strong> <br /><br />".nl2br($contact['content']);
		do_send_mail($mail_to, $mail_subject, $mail_content);

		//Send thank mail back to customer
		$mail_to = $contact['email'];
		$mail_subject = "Thanks letter of dichthuatvuongtuan.com";
		$mail_content = "Hi ".$contact['fullname'].",<br /><br />"
				."Vuong Tuan Translation Company is very happy when recieve your request via website www.dichthuatvuongtuan.com. We will take care it and process in the best way.<br />"
				."Thank you very much!<br /><br />"
				."----------------------------------------------------------------------------<br />"
				."<strong>Vuong Tuan Translation Company</strong><br />"
				."Address: 62/33 Nhat Chi Mai Street, 13th Ward, Tan Binh District, HCM City<br />"
				."Phone: (08) 73008625 - Fax: (08) 73068626 - Mobile: 0974037878<br >"
				."Website: www.dichthuatvuongtuan.com<br />"
				."Email: dichthuatvuongtuan@gmail.com";
		do_send_mail($mail_to, $mail_subject, $mail_content);

		echo "<script>window.location.href='".add_query_arg(array("thank"=>1))."'</script>";
		exit;
		
	}
} 
$thanks = get_param("thank", 0);
if ($thanks == 0) : ?>
    	<div id="content">
            <?php include_once(TEMPLATEPATH . '/topbanner.php'); ?>	
			<?php $p1 = get_post($pid1=61); setup_postdata($p1)?>
			<div class="post clearfix" id="post-<?php the_ID(); ?>">
	    			<h2 class="title" style="text-transform:uppercase"><?php the_title(); ?></h2>
				<div class="entry">
					<?php the_content(); ?>
				</div>
				<div style="margin-left: 30px">
					<?php print ($msg != "") ? "<div style='color:red'>".$msg."</div><br />" : "";?>
		    			<form id="contactform" name="contactform" method="post" action="">
						<div>Full name *</div>
						<div><input type="text" id="fullname" name="contact[fullname]" value="<?php print isset($contact['fullname']) ? $contact['fullname'] : ''?>" /></div>
						<div>Email *</div>
						<div><input type="text" id="email" name="contact[email]" value="<?php print isset($contact['email']) ? $contact['email'] : ''?>" /></div>
						<div>Phone number</div>
						<div><input type="text" id="phone" name="contact[phone]" value="<?php print isset($contact['phone']) ? $contact['phone'] : ''?>" /></div>
						<div>Content *</div>
						<div><textarea style="font-family: inherit" id="content" name="contact[content]" cols="30"><?php print isset($contact['content']) ? $contact['content'] : ''?></textarea></div><br />
						<div>
						<input type="hidden" id="action" name="contact[action]" value="1"/>
						<input type="submit" id="request" name="request" value="Send request" /></div>
					</form>
				</div>
			</div>
			
    		<?php //edit_post_link('Edit this entry.', '<p>', '</p>'); ?>
    		</div>
    	</div>
<?php elseif ($thanks == 1) : ?>
	<div id="content">
	<?php include_once(TEMPLATEPATH . '/topbanner.php'); ?>	
		<div class="entry">
			Congratulation your sending request successfull. We will take care and process in the best way. Please check your mail usualy.<br /> Thank you very much!
		</div>
	</div>
	</div>
<?php endif; ?>
        <?php get_sidebar(); ?>
<?php get_footer(); ?>
